package vooga.actions;

/**
 * Defines how a standard action to control movement should work.
 * These actions add to the velocity and the subtract when done.  These action starts once.
 * @author Jonathan Odom
 *
 */
public class MoveAction implements Action{
	
	protected vooga.entities.Entity myEntity;
	protected double myDefaultMagnitude;
	protected double myDirection;
	protected boolean active;

	/**
	 * Creates an action for the entity to be changed to the direction and defaultMagnitude
	 * @param entity object on which the action occurs
	 * @param direction the Vector direction to move
	 * @param defaultMagnitude the speed the object should move
	 */
	public MoveAction(vooga.entities.Entity entity, double direction, double defaultMagnitude)
	{
		myEntity = entity;
		myDirection = direction;
		myDefaultMagnitude = defaultMagnitude;
		active =false;
	}
	
	public void start()
	{
		if(!active)
		{
			fire();
			active = true;
		}
		
	}
	
	public void stop()
	{
		vooga.geom.Vector newVector = myEntity.getVelocity().add(new vooga.geom.Vector(myDirection,-myDefaultMagnitude));
		myEntity.setVelocity(newVector);
		active = false;
	}
	
	public void fire()
	{
		vooga.geom.Vector newVector = new vooga.geom.Vector(myDirection,myDefaultMagnitude);
		newVector = myEntity.getVelocity().add(newVector);
		myEntity.setVelocity(newVector);
	}
	
}
